package com.liangwj.springbootrabbitmq.rabbit;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * <b>Description:</b> Fanout Exchange Config <br/>
 * Fanout 就是我们熟悉的广播模式或者订阅模式，给Fanout交换机发送消息，绑定了这个交换机的所有队列都收到这个消息。
 * @author Lingwenjun
 * @date 2019/1/14-16:59
 * @version 1.0
 */
@Configuration
public class FanoutRabbitMQConfig {

    @Bean
    public Queue aMessage() {
        return new Queue("fanout.a");
    }
    @Bean
    public Queue bMessage() {
        return new Queue("fanout.b");
    }
    @Bean
    public Queue cMessage() {
        return new Queue("fanout.c");
    }
    @Bean
    public FanoutExchange exchange() {
        return new FanoutExchange("fanoutExchange");
    }
    @Bean
    public Binding bindingExchangeA(Queue aMessage, FanoutExchange exchange) {
        return BindingBuilder.bind(aMessage).to(exchange);
    }
    @Bean
    public Binding bindingExchangeB(Queue bMessage, FanoutExchange exchange) {
        return BindingBuilder.bind(bMessage).to(exchange);
    }
    @Bean
    public Binding bindingExchangeC() {
        return BindingBuilder.bind(cMessage()).to(exchange());
    }
}
